package main

import (
	"fmt"
	"log"
	"runtime/debug"
	"time"
)

func main() {
	go func() {
		defer func() {
			if r := recover(); r != nil {
				log.Printf("Recovered from panic: %v\n", r)
				log.Printf("Stack trace: %s", debug.Stack())
			}
		}()

		// 调用可能引发 panic 的函数
		mayPanic()
	}()

	// 等待 goroutine 执行
	time.Sleep(1 * time.Second)

	fmt.Println("Program continues to run...")
}

func mayPanic() {
	fmt.Println("Inside mayPanic")
	// 引发 panic
	panic("something went terribly wrong")
}
